package com.vancouver.knows.ui.activity.userpost;

import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ViewAnimator;

import com.vancouver.knows.R;
import com.vancouver.knows.business.task.mark.GetUserPostsTaskMark;
import com.vancouver.knows.ui.base.BaseActivity;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by Chris Li on 2016-07-25.
 */
public class ProfileActivity extends BaseActivity {

    public static final String USER_ID_EXTRA = "user_id_extra";

    public static final int HISTORY_VIEW = 0;
    public static final int FOLLOWING_VIEW = 1;

    @Bind(R.id.toolbar_title)
    TextView mToolbarTitle;
    @Bind(R.id.view_animator)
    ViewAnimator mViewAnimator;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile);

        if (getIntent() == null) {
            return;
        }

        String userId = getIntent().getStringExtra(USER_ID_EXTRA);

        ProfileUserPostsPullRefreshView profileHistoryController = new ProfileUserPostsPullRefreshView(this);
        profileHistoryController.loadData(GetUserPostsTaskMark.PAGE_HISTORY, userId, "");
        profileHistoryController.setLayoutParams(new ViewAnimator.LayoutParams(ViewAnimator.LayoutParams.MATCH_PARENT, ViewAnimator.LayoutParams.MATCH_PARENT));
        mViewAnimator.addView(profileHistoryController);

        ProfileUserPostsPullRefreshView profileFollowingController = new ProfileUserPostsPullRefreshView(this);
        profileFollowingController.loadData(GetUserPostsTaskMark.PAGE_FOLLOWING, userId, "");
        profileFollowingController.setLayoutParams(new ViewAnimator.LayoutParams(ViewAnimator.LayoutParams.MATCH_PARENT, ViewAnimator.LayoutParams.MATCH_PARENT));
        mViewAnimator.addView(profileFollowingController);
    }

    @OnClick(R.id.back_icon)
    public void onBackButtonClicked() {
        onBackPressed();
    }

    public void setUsername(String username) {
        mToolbarTitle.setText(username);
    }

    public void setProfileView(int viewToDisplay) {
        mViewAnimator.setDisplayedChild(viewToDisplay);
    }
}
